package com.reggie.mapper;

import com.reggie.dto.OrdersDto;
import com.reggie.pojo.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    List<Orders> findAll(Integer page, Integer pageSize, String number, String beginTime, String endTime);

    boolean editStatus(Integer status, Long id);

    @Insert("INSERT INTO orders(id, number, status, user_id, address_book_id, order_time, checkout_time, pay_method,  amount, remark, phone, address, user_name, consignee) " +
            "values (#{id}, #{number}, #{status}, #{userId}, #{addressBookId}, now(), now(), #{payMethod}, #{amount}, #{remark}, #{phone}, #{address}, #{userName}, #{consignee})")
    Integer add(Orders orders);

    @Select("SELECT * FROM orders WHERE user_id=#{userId}")
    List<OrdersDto> findByUserId(Integer page, Integer pageSize, Long userId);

    @Select("SELECT * From orders WHERE id=#{id}")
    Orders find(Long id);
}
